﻿
<?php

    if(!empty($_POST)){
        // print_r($_POST['check']);exit;
             //把表单的值存放到这两个变量中
         $name=$_POST['name'];
         $password=$_POST['password'];


                 if(!empty($_COOKIE['password'])&&$_COOKIE['password']==$_POST['password']){

                    $password=$_COOKIE['password'];
                 }



        //这里缺少对数据库链接的优化处理要补上 李哥笔


                     //把符合条件的记录查询出来
        $sql="SELECT * FROM  `admin` where `name` = '$name' and `password` = '$password'";
                     //定义一个变量存放结果集
        $data=mysqli_query($link,$sql);

                        //mysqli_fetch_assoc是从结果集获取数据
        $result=mysqli_fetch_assoc($data);




        if(!empty($result)){


        if(!empty($_POST['check'])){

                 setcookie('name',$name,time()+3600*24*7);

                         setcookie('password',$password,time()+3600*24*7);

            }else{

                setcookie('name','',-1);
                setcookie('password','del.php',-1);
            }



                $_SESSION['admin'] = $result;

             header('location:index.php?c=index&a=index');


        }else{

            echo '<script>alert("连接失败");history.go(-1) </script>';
        }

    }








 //载入后台公共视图
 // include_once (VIEW_PATH.'home/index/index.html');
 include_once ('protected/View/home/admin/login.html');

?>